{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "7d38155d",
   "metadata": {},
   "source": [
    "### Multiple Shooting Layers"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "16f7165f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The autoreload extension is already loaded. To reload it, use:\n",
      "  %reload_ext autoreload\n"
     ]
    }
   ],
   "source": [
    "import torchdyn\n",
    "import torch\n",
    "import torch.nn as nn\n",
    "import matplotlib.pyplot as plt\n",
    "from torchdyn.core import MultipleShootingLayer, MultipleShootingProblem\n",
    "from torchdyn.numerics import Lorenz\n",
    "\n",
    "import torchdiffeq\n",
    "import time \n",
    "%load_ext autoreload\n",
    "%autoreload 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "c39abef8",
   "metadata": {},
   "outputs": [],
   "source": [
    "x0 = torch.randn(8, 3) + 15\n",
    "t_span = torch.linspace(0, 3, 3000)\n",
    "sys = Lorenz()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "967fbf3e",
   "metadata": {},
   "outputs": [],
   "source": [
    "for sensitivity in ['autograd', 'adjoint', 'interpolated_adjoint']:\n",
    "    mshooting = MultipleShootingProblem(sys, solver='zero', sensitivity=sensitivity)\n",
    "    t_eval, sol = mshooting(x0, t_span)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "dddc49b3",
   "metadata": {},
   "outputs": [],
   "source": [
    "for sensitivity in ['autograd', 'adjoint', 'interpolated_adjoint']:\n",
    "    mshooting = MultipleShootingLayer(sys, solver='zero', sensitivity=sensitivity)\n",
    "    t_eval, sol = mshooting(x0, t_span)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "torchdyn",
   "language": "python",
   "name": "torchdyn"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
